using UnityEngine;
using System.Collections;

public class PlaySoundOnWalk_Simple_Loop : MonoBehaviour {
	
	public AudioSource source;
	public float delayDeltaTime = 0.7f;
	
	private float delta = 0.0f;
	
	// Update is called once per frame
	void Update () {
		if (Input.GetKey("w") || Input.GetKey("s") || Input.GetKey("a") || Input.GetKey("d")) {
			if (delta >= delayDeltaTime) {
				playSound();
				delta = 0;
			} else {
				delta += Time.deltaTime;
			}
		} else {
			source.Stop();	
		}
	}
	
	public void playSound() {
		if (!source.isPlaying) {
			source.Play();
		}
	}
}
